#include "LifeForm.h"

LifeForm::LifeForm():

    _speed_x(0),
    _speed_y(0),
    _UpDown(true),
    _LeftRight(true)
{}


void LifeForm::initialise(int pos_x, int pos_y, int direction_x, int direction_y,
                          float speed_x, float speed_y, int ID )
{
    GameElement::initialise(pos_x, pos_y, direction_x, direction_y, ID);

    _speed_x = speed_x;
    _speed_y = speed_y;
}

void LifeForm::update()
{
    if( (_pos_x%50==0) && (_pos_y%50==0))
    {
        _UpDown = true;
        _LeftRight = true;
    }

    else if( (_pos_x%50==0) && !(_pos_y%50==0))
    {
        _direction_x = 0;
        _LeftRight = false;
    }

    else if( !(_pos_x%50==0) && (_pos_y%50==0))
    {
        _direction_y = 0;
        _UpDown = false;
    }

    //moves the life form
    _pos_x += _speed_x * _direction_x;
    _pos_y += _speed_y * _direction_y;

}

void LifeForm::move_up()
{
    if(_UpDown) _direction_y = -1;
}

void LifeForm::move_down()
{
    if(_UpDown) _direction_y = 1;
}

void LifeForm::move_left()
{
    if(_LeftRight) _direction_x = -1;
}

void LifeForm::move_right()
{
    if(_LeftRight) _direction_x = 1;
}

void LifeForm::still_y()
{
    if ( _pos_x%50==0 && _pos_y%50==0 )
        _direction_y = 0;
}

void LifeForm::still_x()
{
    if ( _pos_x%50==0 && _pos_y%50==0 )
        _direction_x = 0;
}




